import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/4 20:51
 * @description 逆向思维，由于加倍次数有限，那么应当使数较大时再加倍
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.minMoves(19, 2);
    }
    public int minMoves(int target, int maxDoubles) {
        int ans = 0;
        while (target > 1) {
            if (maxDoubles == 0) {
                return ans + target - 1;
            }
            if ( target % 2 == 1) {
                target--;
                ans++;
            }
            // 变偶数后，我们使用加倍，让其折半
            maxDoubles--;
            target /= 2;
            ans++;
        }
        return ans;
    }
}
